home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 223 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,comp.std.c
  4. Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
  5. Date: Tue, 30 Jan 96 00:13:24 GMT
  6. Organization: none
  7. Message-ID: <822960804snz@genesis.demon.co.uk>
  8. References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM> <KANZE.96Jan29201312@slsvewt.lts.sel.alcatel.de>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <KANZE.96Jan29201312@slsvewt.lts.sel.alcatel.de>
  15.            kanze@lts.sel.alcatel.de "James Kanze US/ESC 60/3/141 #40763" writes:
  16.  
  17. >Again, I think that one should make the distinction (at least in
  18. >comp.lang.c) between undefined undefined by the standard, and really
  19. >undefined.
  20.  
  21. I don't think you'll find it easy to make such a distinction.
  22.  
  23.   The distinction is not defined in the standard, but is
  24. >very present in real life.  Thus, dereferencing a NULL pointer is
  25. >undefined, and while an implementation is free to define it if it
  26. >likes, in practice, none will define it to do anything good.  Adding a
  27. >third parameter to main is also undefined according to the C standard,
  28. >but most Unix compilers (and maybe others) do define it in a very
  29. >useful way; as far as I know, Posix may even define it so.
  30.  
  31. Frankly the 3rd parameter is to be avoided these days - treat it the
  32. same as void main. POSIX doesn't support it; the correct POSIX way
  33. is to use the extern char **environ variable.
  34.  
  35. >Although I find it hard to explain precisely the difference,
  36.  
  37. Historical usage.
  38.  
  39. >I would
  40. >generally consider counting on implementation defined behavior in
  41. >derefencing the null pointer bad practice.  On the other hand, using
  42. >the added parameter to main wouldn't particularly bother me,
  43. >especially if, as is the case in most of my applications, the program
  44. >is intimely bound to Unix anyway.
  45.  
  46. That is the same argument as a DOS programmer using void main(). In both
  47. cases the fix is trivial and should be done to uphold the general
  48. principle that if there is a viable portable way of doing something, use
  49. it. OK, using environ doesn't make the program generally portable across
  50. ANSI platforms but it is still more portable (meets more standards giving
  51. you a higher level of guarantee) than the 3 parameter main.
  52.  
  53. >This is always a delicate line.  A Windows program using far and near
  54. >pointers: I don't believe they can avoid it, and the program surely
  55. >won't run on anyother platform without major modifications.  A filter
  56. >program invoked from the DOS command line: I'd consider the use of far
  57. >and near a major flaw, and would heartily condemn a design which
  58. >required it.
  59.  
  60. That doesn't violate the principle of coding portably where it is viable.
  61. It just may not always be viable.
  62.  
  63. >I agree, but...
  64. >
  65. >Try naming a global function read, and see what happens (on most
  66. >compilers, anyway).  In fact, the Posix standard requires it, and
  67. >thus, you cannot be Posix compliant without encroaching upon the user
  68. >name space.  (For example.  I'm sure that most other systems will have
  69. >similar constraints.)
  70.  
  71. Yes, but that namespace need only be encroached upon if you include
  72. POSIX (rather than ANSI) specific header files. As soon as you do that you
  73. invoke undefined behaviour according to the C standard hence the
  74. implementation is free to follow the POSIX rules. The other issue is
  75. identifiers with external linkage. If the system doesn't link an identifier
  76. *defined* by the program to the system library (common linker behaviour)
  77. this needn't be a problem.
  78.  
  79. The same principle can be applied to near/far under DOS compilers. A
  80. strictly conforming implementation can implement them if they are only
  81. activated on the inclusion of a non-ANSI header file.
  82.  
  83. >Well, I'm not sure that I'd consider Posix a fossil of an era long
  84. >past, although it certainly reflects a long history.
  85. >
  86. >I'm not sure where to draw the line.  Discussions of `read' certainly
  87. >don't belong in c.l.c.  But simply telling someone that his system is
  88. >broken because printf stopped working when he declared a global read
  89. >is not going to help anyone, even if, strictly speaking, it is true
  90. >according to the standard.
  91.  
  92. The point is that even on a POSIX system such a program should work
  93. unless the program includes something like unistd.h. At that point
  94. the behaviour of the program is no longer defined by the ANSI standard,
  95. so doesn't prevent the system being ANSI conformant.
  96.  
  97. -- 
  98. -----------------------------------------
  99. Lawrence Kirby | fred@genesis.demon.co.uk
  100. Wilts, England | 70734.126@compuserve.com
  101. -----------------------------------------
  102.